{% extends "public/layout.html" %}



{% block sidebar %}
    {% include "public/cmdb_left.html" %}
{% endblock %}


{% block custom_css %}
    <style>
        .btn_mod{font-size: 14px;padding:2px 6px;}
    </style>
{% endblock %}

{% block body %}
    <table id="idc-table" class="table table-striped" style="width:1300px;">
        <caption>
            <a class="btn btn-default" href="/resources/idc/add/" role="button">添加IDC</a>

        </caption>
        <tr>
            <th>#</th>
            <th>IDC字母简称</th>
            <th>idc名称</th>
            <th>IDC详细地址</th>
            <th>客服电话</th>
            <th>邮件地址</th>
            <th>IDC接口人</th>
            <th>接口人电话</th>
            <th>实际机柜数</th>
            <th>合同机柜数</th>
            <th>操作</th>
        </tr>
        {% for idc in idcs %}
            <tr>

                <td>{{ loop.index }}</td>
                <td>{{ idc.name }}</td>
                <td>{{ idc.idc_name }}</td>
                <td>{{ idc.address }}</td>
                <td>{{ idc.phone }}</td>
                <td>{{ idc.email }}</td>
                <td>{{ idc.user_interface }}</td>
                <td>{{ idc.user_phone }}</td>
                <td>{{ idc.rel_cabinet_num }}</td>
                <td>{{ idc.pact_cabinet_num }}</td>
                <td>
                    <a href="/resources/idc/modify/{{ idc.id }}" class="btn btn-primary btn_mod">修改</a>
                    <a href="{{ idc.id }}" class="btn btn-danger btn_mod btn_delete">删除</a>
                </td>
            </tr>
        {% endfor %}
    </table>
{% endblock %}

{% block js %}
    <script>
    function getList() {
        $.post('/resources/idc/list', function (data) {
            var data_list = JSON.parse(data)
            // console.log(data_list)
            var tmp = '<caption><a class="btn btn-default" href="/resources/idc/add/" role="button">添加IDC</a></caption>'
            tmp += '<tr><th>#</th><th>IDC字母简称</th><th>idc名称</th>'
            tmp += '<th>IDC详细地址</th>'
            tmp += '<th>客服电话</th>'
            tmp += '<th>邮件地址</th>'
            tmp += '<th>IDC接口人</th>'
            tmp += '<th>接口人电话</th>'
            tmp += '<th>实际机柜数</th>'
            tmp += '<th>合同机柜数</th>'
            tmp += '<th>操作</th></tr>'
            $.each(data_list, function (index, value) {
                /*
                console.log(index)
                console.log(value[0])
                console.log(value['user_phone'])
                console.log(value['phone'])
                */
                var idc_index = index + 1
                tmp += '<tr>'
                tmp += '<td>'+idc_index+'</td>'
                tmp += '<td>'+value['name']+'</td>'
                tmp += '<td>'+value['idc_name']+'</td>'
                tmp += '<td>'+value['address']+'</td>'
                tmp += '<td>'+value['phone']+'</td>'
                tmp += '<td>'+value['email']+'</td>'
                tmp += '<td>'+value['user_interface']+'</td>'
                tmp += '<td>'+value['user_phone']+'</td>'
                tmp += '<td>'+value['rel_cabinet_num']+'</td>'
                tmp += '<td>'+value['pact_cabinet_num']+'</td>'
                tmp += '<td>'
                tmp += '<a href="/resources/idc/modify/'+value['id']+'" class="btn btn-primary btn_mod">修改</a>'
                tmp += '<a href="'+value['id']+'" class="btn btn-danger btn_mod btn_delete">删除</a>'
                tmp += '</td>'
                tmp += '<tr>'
            })
            $('#idc-table').html(tmp)
        })
    }

    $('.btn_delete').click(function () {
    //$(document).on('click', '.btn_delete', function (){
        var id = $(this).attr('href')
        // console.log("id:", id)

        swal({
            title: "确定要删除吗？",
            text: "即将删除这条IDC信息",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "删除",
            cancelButtonText: "取消",
            closeOnConfirm: false
        }, function(){
            // getList()

            $.get("/resources/idc/dodelete?id="+id, function (data) {
                if (data == "ok") {
                    // $.get("/resources/idc/")
                    getList()
                    swal("删除成功", "", "success");
                }
                else {
                    swal("删除失败", "", "error");
                }

            })

        });
        return false
    })

    </script>
{% endblock %}

